//导入
const EventEmitter = require('events').EventEmitter;
//定义类
function Dog(name,energy){
  let _name = name,
      _energy = energy,
      that = this;

  EventEmitter.call(this);
//定时器
  let timer = setInterval(()=>{
    if(_energy>0){
      that.emit('bark');
      _energy--;
    }
    else{
      clearInterval(timer);
    }
  },1000);
  //两个公开方法返回私有属性
  this.name = ()=>_name;
  this.energy =()=>_energy;
}

Dog.prototype = EventEmitter.prototype;

module.exports = Dog;
